<template>
  <div class="dialog">
    <el-dialog
      :title="title"
      :visible.sync="visible"
      :close-on-click-modal="false"
      width="45%"
      top="20vh"
      @close="closeDialog"
    >
      <el-form
        :model="createForm"
        label-width="160px"
        label-suffix=":"
        class="searchw"
        ref="createForm"
        :rules="rule"
      >
        <el-row :gutter="24">
          <el-col :span="22">
            <el-form-item label="分类名称" prop="name">
              <el-input
                v-model.trim="createForm.name"
                placeholder="请输入分类名称"
                :disabled="title == '配件分类详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="22">
            <el-form-item label="上级名称" prop="parentName">
              <el-cascader
                v-model="createForm.parentName"
                :options="topParentList"
                @change="getChange"
                placeholder="请输入上级名称"
                :disabled="title == '配件分类详情'"
              ></el-cascader>
              <!-- <el-input
                v-model.trim="createForm.parentName"
                placeholder="请输入上级名称"
              ></el-input> -->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="22">
            <el-form-item label="热度" prop="hot">
              <el-input
                v-model.trim="createForm.hot"
                type="number"
                min="0"
                placeholder="请输入热度"
                :disabled="title == '配件分类详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog()">关 闭</el-button>
        <el-button
          type="primary"
          @click="confirmData('createForm')"
          v-if="title != '配件分类详情'"
          >保 存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'addBrand',
  props: {
    row: {
      type: Object,
      default: {}
    },
    title: {
      type: String,
      default: ''
    },
    value: {
      type: Boolean,
      default: false
    },
    topParentList:{
      type: Array,
      default: []
    }
  },
  data() {
    return {
      visible: true,
      createForm: {
        name: '',
        hot: '',
        parentName: '',
        topName:"",
        gatherTime: ''
      },
      rule:{
        name: [
          { required: true, message: '请输入分类名称', trigger: 'blur' },
        ],
        parentName: [
          { required: true, message: '请输入上级名称', trigger: 'blur' },
        ],
        hot:[
          { required: true, message: '请输入热度', trigger: 'blur' },
        ]
      }
    }
  },
  created() {
    if(this.row.id){
      this.createForm = this.row
    }
  },
  mounted() {},
  methods: {
     /**
     * 获取上级分类和一级分类
     */
    getChange(val) {
      this.createForm.topName = val[0]
      this.createForm.parentName = val[1]
    },
    confirmData(formName) {
      this.$refs[formName].validate((valid) => {
        if(valid) {
          this.$emit('ok', this.createForm)
        }
      })
    },
    closeDialog() {
      this.$emit('cancle')
    }
  }
}
</script>
<style scoped lang="less">
.el-select,.el-input-number,.el-cascader--medium {
  width: 100%!important;;
  .el-input{
    width: 100%!important;;
  }
}
</style>
